var instanceId = T.p("instanceId");
$(function () {
    $("#jqGrid").jqGrid({
        url: '../scheduleInstanceDtl/list',
        datatype: "json",
        postData: {instanceId: instanceId},
        colModel: [
            {label: 'id', name: 'id', width: 50, key: true, hidden: true},
            {label: '作业ID', name: 'workId', width: 30},
            {label: '作业名称', name: 'workName', width: 60},
            {label: '作业项ID', name: 'workItemId', width: 40},
            {label: '作业项名称', name: 'workItemName', width: 40},
            {
                label: '运行状态', name: 'runStatus', width: 40, formatter: function (value, options, row) {
                    var rt;
                    if (value == 1) {
                        rt = '<span class="label label-default">待执行</span>';
                    } else if (value == 2) {
                        rt = '<span class="label label-primary">再执行</span>';
                    } else if (value == 3) {
                        rt = '<span class="label label-info">执行中</span>';
                    } else if (value == 4) {
                        rt = '<span class="label label-success">执行完成</span>';
                    }
                    return rt;
                }
            },
            {label: '执行IP', name: 'execIp', width: 70},
            {label: '參數', name: 'params', width: 100},
            {label: '总数', name: 'totalNum', width: 40},
            {label: '成功数', name: 'succNum', width: 40},
            {
                label: '失败数', name: 'errNum', width: 50, formatter: function (value, options, row) {
                    var show = 0;
                    if (value >= 1) {
                        show = '<span class="label label-danger pointer" onclick="vm.showError(' + row.id + ')">' + value + '</span>';
                    }
                    return show;
                }
            },
            {label: '更新时间', name: 'updateTime', width: 80}
        ],
        viewrecords: true,
        height: 800,
        rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.data",
            page: "page.pageNo",
            total: "page.pageCount",
            records: "page.count"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        isShowCond: false,
        btnText: '查询',
        qryForm: {}
    },
    methods: {
        reset: function () {

        },
        query: function () {
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {},
                page: 1
            }).trigger("reloadGrid");
        },
        toggle: function () {
            this.isShowCond = !this.isShowCond;

            if (this.isShowCond == true) {
                this.btnText = "隐藏"
            } else if (this.isShowCond == false) {
                this.btnText = "查询"
            }

        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }

            location.href = "scheduleInstanceDtl_add.html?id=" + id;
        },
        back: function (event) {
            history.go(-1);
        },
        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: "../scheduleInstanceDtl/delete",
                    data: JSON.stringify(ids),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        }
    }
});
